<template>
  <view class="wrap">
    <view class="search">
      <u-search v-model="keywords" @custom="search" @search="search"></u-search>
    </view>
    <scroll-view class="scroll-list" scroll-y="true">
      <view class="uni-list">
        <uni-view class="uni-list-cell">
          <view
            class="uni-media-list"
            @click="navTo('/pages/sys/msg/list-item?type=notice')"
          >
            <view class="home-icon icon-color03">
              <i class="iconfont icon-tongzhi1"
                ><u-badge
                  type="error"
                  :count="todoForm.noticeCount || 0"
                ></u-badge
              ></i>
            </view>
            <uni-view class="uni-media-list-body">
              <uni-view class="uni-media-list-text-top"
                ><span>通知公告</span
                ><span style="font-size: 26rpx; color: #999999">{{
                  todoForm.notice ? todoForm.notice.createTime : ''
                }}</span></uni-view
              >
              <uni-view class="uni-media-list-text-bottom">
                <uni-text
                  ><span>{{
                    todoForm.notice ? todoForm.notice.noticeTitle : ''
                  }}</span></uni-text
                >
              </uni-view>
            </uni-view>
          </view>
        </uni-view>
        <view
          class="uni-list-cell"
          @click="navTo('/pages/sys/msg/list-item?type=news')"
        >
          <uni-view class="uni-media-list">
            <view class="home-icon icon-color04">
              <i class="iconfont icon-xinwen"
                ><u-badge
                  type="error"
                  :count="todoForm.newsCount || 0"
                ></u-badge
              ></i>
            </view>
            <uni-view class="uni-media-list-body">
              <uni-view class="uni-media-list-text-top"
                ><span>新闻动态</span
                ><span style="font-size: 26rpx; color: #999999">{{
                  todoForm.news ? todoForm.news.createTime : ''
                }}</span></uni-view
              >
              <uni-view class="uni-media-list-text-bottom">
                <uni-text
                  ><span>{{
                    todoForm.news ? todoForm.news.noticeTitle : ''
                  }}</span></uni-text
                >
              </uni-view>
            </uni-view>
          </uni-view>
        </view>
        <view
          class="uni-list-cell"
          @click="navTo('/pages/sys/msg/examine-item')"
        >
          <uni-view class="uni-media-list">
            <view class="home-icon icon-color04">
              <i class="iconfont icon-xinwen"
                ><u-badge type="error" :count="todoForm.count || 0"></u-badge
              ></i>
            </view>
            <uni-view class="uni-media-list-body">
              <uni-view class="uni-media-list-text-top"
                ><span>我的待办</span
                ><span style="font-size: 26rpx; color: #999999">{{
                  todoForm.businessUserTask
                    ? todoForm.businessUserTask.createTime
                    : ''
                }}</span></uni-view
              >
              <uni-view class="uni-media-list-text-bottom">
                <uni-text
                  ><span>{{
                    todoForm.businessUserTask
                      ? todoForm.businessUserTask.message
                      : ''
                  }}</span></uni-text
                >
              </uni-view>
            </uni-view>
          </uni-view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      keywords: '',
      todoForm: {
        notice: {},
        news: {},
        businessUserTask: {},
      },
    }
  },
  onLoad() {
    this.$u.api.getHome().then((res) => {
      if (res.code == '200') {
        this.todoForm = res.data
      }
    })
  },
  onShow() {
    this.$u.api.getHomeCount().then((res) => {
      if (res.code == '200') {
        let count = res.data > 0 ? (res.data > 99 ? '99+' : res.data + '') : 0
        uni.setTabBarBadge({
          index: 0,
          text: count,
        })
      }
    })
    this.$u.api.getHome().then((res) => {
      if (res.code == '200') {
        this.todoForm = res.data
      }
    })
  },
  methods: {
    navTo(url) {
      uni.navigateTo({
        url: url,
      })
    },
    search(value) {
      this.$u.toast('搜索内容为：' + value)
    },
  },
}
</script>
<style lang="scss">
@import '../../../common/uni.css';
page {
  background-color: #f5f5f5;
}
.wrap .search {
  background: #ffffff;
}
.uni-title {
  font-size: 30rpx;
  color: #333333;
  padding: 10px;
  background: #fff;
  border-top: 1px solid #ededed;
  margin-top: 20rpx;
}
.uni-media-list {
  padding: 15px 15px;
}
.uni-media-list-body {
  height: 96rpx;
  padding-left: 20rpx;
}
.uni-media-list-text-top {
  height: 40rpx;
  overflow: hidden;
  width: 100%;
  line-height: 40rpx;
  font-size: 32rpx;
  display: flex;
  justify-content: space-between;
}

.uni-media-list-text-bottom {
  width: 100%;
  font-size: 26rpx;
  color: #666666;
  span {
    margin-right: 10rpx;
  }
}
</style>
